﻿Namespace DB
    Public Class DBTableList
        Inherits System.ComponentModel.BindingList(Of DBTable)

        Sub New(ByVal MetisCore As MetisCore)
            Dim OraReader As OracleDataReader
            Dim OraCmd As OracleCommand
            OraCmd = New OracleCommand("SELECT table_name, 0 FROM user_tables " & _
                                       "UNION " & _
                                       "SELECT view_name, 1 FROM user_views ", MetisCore.Connection)

            OraReader = OraCmd.ExecuteReader
            Do While OraReader.Read
                If OraReader.GetInt32(1) = DBTableType.Table Then
                    Me.Add(New DBTable(MetisCore, OraReader.GetString(0), DBTableType.Table, MetisLoadState.NotLoaded))
                Else
                    Me.Add(New DBTable(MetisCore, OraReader.GetString(0), DBTableType.Query, MetisLoadState.NotLoaded))
                End If
            Loop
            OraReader.Close()

        End Sub

        Function FindTable(ByVal TableName As String) As DBTable
            For Each Item As DBTable In Me
                If Item.TableName.Equals(TableName, StringComparison.OrdinalIgnoreCase) Then
                    Return Item
                End If
            Next
        End Function

    End Class
End Namespace

